<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    var obj = {
      a:10
    }
    var a=20;

    Object.defineProperty(obj,'a',{
      get(){  //getter  取值 拦截器
        console.log("我拦截了obj对象a属性的获取操作");
        return a;
      },
      set(value){
        // setter 赋值 拦截器
        console.log("这是设置的值",+value);
        a=value;
        console.log("我拦截了obj对象a属性的赋值操作")
      }
    })
    console.log( obj.a );
    obj.a=50;
    console.log(obj.a);
  </script>
</body>
</html>